import { Injectable } from '@angular/core';

import {
    HttpEvent, HttpInterceptor, HttpHandler, HttpRequest
} from '@angular/common/http';

import { Observable } from 'rxjs';
import { TokenService } from '../core/service/token.service';


@Injectable()
export class LoginInterceptor implements HttpInterceptor {
    constructor(private tokenService: TokenService) {}
    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        console.log(1);
        if (this.tokenService.getFlag()) {
            const loginReq = req.clone({
                url: '/login'
            });
            return next.handle(loginReq);
        }
        return next.handle(req);
    }
}
